const nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({
  host: 'smtp.163.com',
  port: 25,
  secure: false, // true for 465, false for other ports
  auth: {
    user: 'ybfweb@163.com', // generated ethereal user
    pass: 'bing2840' // generated ethereal password
  }
});

// setup email data with unicode symbols
let mailOptions = {
  from: 'ybfweb@163.com', // sender address
  to: '284056259@qq.com', // list of receivers
  subject: '远程面试邀请', // Subject line
  text: '', // plain text body
  html: '<a href="http://baidu.com">点击跳转</a>' // html body
};

function sendMail(msg) {
	// send mail with defined transport object
	return new Promise((resolve,reject)=>{
		transporter.sendMail(Object.assign(mailOptions,msg), (error, info) => {
			if (error) {
				return console.log(error);
			}
			resolve(info);
			console.log('Message sent: %s', info.messageId);
			console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
		});
	});
}

module.exports= sendMail;